package sample1;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;

public class ServletSample1 extends HttpServlet{
	private static final long serialVersionUID = -3316552618231595388L;

	protected void doGet(HttpServletRequest request,
			HttpServletResponse response)
	throws ServletException,IOException{
		
		response.setContentType("text/html;charset=UTF-8");
		request.setCharacterEncoding("UTF-8");
		Resource res = new ClassPathResource("conf/bean-conf.xml");
		
		DefaultListableBeanFactory factory = new DefaultListableBeanFactory();
		XmlBeanDefinitionReader bdr = new XmlBeanDefinitionReader(factory);
		bdr.loadBeanDefinitions(res);

		BeanSample1 bs1 = (BeanSample1)factory.getBean("sample1");
		PrintWriter out = response.getWriter();
		out.println("<html><head></head>");
		out.println("<body>");
		bs1.doSample(out);
		out.println("</body></html>");
	}
}
